package com.fs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.mapper.ProductMapper;
import com.fs.pojo.Customer;
import com.fs.pojo.Product;
import com.fs.service.ProductService;
import com.fs.vo.Condition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.parsing.ProblemReporter;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author hyy
 * @version 1.0
 * @description: 商品服务层实现
 * @date 2024/10/17 19:21
 */
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;
    @Override
    public Page<Product> queryProducts(Condition<Product> condition) {
        Page<Product> page = new Page<>(condition.getPage(),condition.getCount());
        //构建条件构造器
        LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<Product>();
        Product product=condition.getSearch();
        if (Objects.nonNull(product)){
            //供应商姓名模糊查询条件
            wrapper.eq(product.getProductId()!=null,Product::getProductId,product.getProductId())
                    //编号查询
                    .like(product.getProductName()!=null,Product::getProductName,product.getProductName())
                    //品牌
                    .eq(product.getBrand()!=null,Product::getBrand,product.getBrand());
        }
        return productMapper.selectPage(page,wrapper);
    }
}
